package leetcode.code2008;

import java.util.Arrays;

import leetcode.IDebug;

//执行用时：117 ms, 在所有 Java 提交中击败了7.41%的用户
//
//内存消耗：64 MB, 在所有 Java 提交中击败了15.27%的用户
//
//通过测试用例：84 / 84
public class Solution implements IDebug {

	public long maxTaxiEarnings(int n, int[][] rides) {
		long[] dp = new long[n + 1];
		Arrays.sort(rides, (a, b) -> a[1] - b[1]);
		for (int i = 1, p = 0; i <= n; i++) {
			long maxi = dp[i - 1];
			for (; p < rides.length && rides[p][1] == i; p++) {
				int[] ride = rides[p];
				maxi = Math.max(maxi, ride[1] - ride[0] + ride[2] + dp[ride[0]]);
			}
			dp[i] = maxi;
		}
		return dp[n];
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
